<?php
class User extends ActiveRecord {
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	public function tableName() {
		return 'users';
	}
	public function rules() {
		return array(
			array('username, password, email, status', 'required'),
			array('username, email','unique'),//@todo it should be based on module settings
			array('username','length', 'max' => 32),
			array('email, password', 'length', 'max' => 128),
			array('password','length', 'min' => 6),
			//@todo stronger password check on insert
			array('status', 'length', 'max' => 12),
			//@todo check if status in given enum vals
			array('email','email'),
		);
	}
	public function validatePassword($password) {
		return md5($password) === $this->password;
	}
	/**
	 * relations raises event 'users.models.User.relations' to retrieve
	 * eventual relations to models of another module
	 * 
	 * @access public
	 * @return void
	 */
	public function relations() {
		$ev = new ExtEvent;
		$ev->tryDefault = FALSE;
		Yii::app()->modulehook->raiseEvent('modules.users.models.User.relations',$ev);
		if(is_array($ev->data)) {
			return $ev->data;
		}
		return array();
	}
}
